home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / pcx_c.zip / VGR.C < prev    next >
C/C++ Source or Header  |  1988-04-17  |  2KB  |  120 lines

  1. /*    VGR.c    -  Routines that access the BIOS or are otherwise
  2.                 related to video, but not board specific.
  3. */
  4.  
  5.  
  6. #define ALLOCATE
  7. #include "lib.h"
  8. #include "vgr.h"
  9.  
  10.  
  11. /*    VGR_GET_BOARD
  12.  
  13.     Partly by Dan Laurence, 
  14.     from MicroEMACS, IBMPC.C, page 5 
  15.     Hercules test by Larry Fogg, 
  16.     from MicroC, jan-feb '88, page 26.
  17.  
  18.     It's difficult for me to test this...
  19.     My ATI EGA Wonder is basically either a
  20.     HERC or EGA board... Besides that, there's
  21.     no perfect algorithm available for this 
  22.     problem...
  23. */
  24.  
  25. int vgr_get_board()
  26. {
  27.     int i;
  28.     REGS r;
  29.  
  30.     /* Check for MONO */
  31.     sysint( 0x11, &r, &r );
  32.     if ( ( (r.ax >> 4) & 0x03 ) == 0x03 )
  33.     {  for ( i=0; i < 0x1000; i++ )
  34.           if ( inportb( 0x3ba ) & 0x80 )
  35.              return TYPE_HERC;
  36.        return TYPE_MDA;
  37.     };
  38.  
  39.     /* Check for EGA
  40.     */
  41.     r.ax = 0x1200;
  42.     r.bx = 0xff10;
  43.     sysint( 0x10, &r, &r );
  44.     if ( !(r.bx & (~0x0103)) )    /* might be EGA...   */
  45.        return TYPE_EGA;
  46.     else return TYPE_CGA; /* should be CGA, but...  */
  47. }
  48.  
  49.  
  50. int vgr_mode( mode )
  51. unsigned char mode;
  52. {
  53.     REGS r;
  54.  
  55.     r.ax = mode;
  56.     sysint( 0x10, &r, &r );
  57.  
  58.     return OK;
  59. }
  60.  
  61.  
  62. /*    adapted from jan/feb microcornucopia, page 85
  63.     by Gary Entsminger. Gary's ref: Bresenham's algorithm,
  64.     from Advanced Turbo C by Herbert Schildt.
  65. */
  66.  
  67. void vgr_line( x1, y1, x2, y2, color )
  68. int x1, x2, y1, y2, color;
  69. {
  70.     int t, distance, xerr, yerr, dx, dy, ix, iy;
  71.  
  72.     ix = (dx = x2-x1) < 0 ? (dx = -dx, -1) : !!dx;
  73.     iy = (dy = y2-y1) < 0 ? (dy = -dy, -1) : !!dy;
  74.  
  75.     distance = dx > dy ? dx : dy;
  76.  
  77.     xerr = yerr = 0;
  78.     for ( t = -2; t < distance; t++ )
  79.     {  VGR_SET( x1, y1, color );
  80.  
  81.        xerr += dx;
  82.        yerr += dy;
  83.  
  84.        if ( xerr > distance )
  85.        {  xerr -= distance;
  86.           x1   += ix;
  87.        };
  88.  
  89.        if ( yerr > distance )
  90.        {  yerr -= distance;
  91.           y1   += iy;
  92.        };
  93.     };
  94. }
  95.  
  96.  
  97. void vgr_rectangle( x1, y1, x2, y2, color )
  98. int x1, x2, y1, y2, color;
  99. {
  100.     vgr_line( x1, y1, x1, y2, color );
  101.     vgr_line( x1, y2, x2, y2, color );
  102.     vgr_line( x2, y2, x2, y1, color );
  103.     vgr_line( x2, y1, x1, y1, color );
  104. }
  105.  
  106.  
  107. void vgr_point( x2, y2, color )
  108. int x2, y2, color;
  109. {
  110.     static int x1=0, y1=0;
  111.  
  112.     if ( color != -1 )
  113.        vgr_line( x1, y1, x2, y2, color );
  114.  
  115.     x1 = x2;
  116.     y1 = y2;
  117.     return;
  118. }
  119.  
  120.